package com.wenjie.controller;

import com.wenjie.original.entity.common.vo.RestBaseVo;
import com.wenjie.original.entity.vo.User.UserUpOrAddVo;
import com.wenjie.original.entity.vo.User.UserVo;
import com.wenjie.original.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("客户信息")
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @ApiOperation("查询接口")
    @PostMapping("/list")
    public RestBaseVo<UserVo.ResVo> list(@RequestBody @Validated UserVo.SelVo selVo) {
        return userService.list(selVo, UserVo.ResVo.class);
    }

    @ApiOperation("添加接口")
    @PostMapping("/add")
    public void add(@RequestBody @Validated UserUpOrAddVo.AddVo addVo) {
        userService.save(addVo);
    }

    @ApiOperation("修改接口")
    @PostMapping("/up")
    public void up(@RequestBody @Validated UserUpOrAddVo.UpVo upVo) {
        userService.updateById(upVo);
    }

    @ApiOperation("删除接口")
    @PostMapping("/del")
    public void del(@RequestBody @Validated Long id) {
        userService.removeById(id);
    }

}
